package test;

public class test1 {
    public static void main(String[] args) {
        ArrayQueue queue=new ArrayQueue(15);
        queue.add(1);
        queue.add(2);
        System.out.println(queue.get());
        System.out.println(queue.peek());
        System.out.println(queue);
    }
}
class ArrayQueue{

    int[] queue;
    int front=-1;//头部指针
    int fear=-1;//尾部指针

    public ArrayQueue(int maxSize){//构造函数
        queue=new int[maxSize];
    }

    public boolean isFull(){//判满
        return fear==queue.length-1;
    }

    public boolean isEmpty(){//判空
        return fear==front;
    }

    public boolean add(int item){

        if(isFull())
            return false;

        fear++;
        queue[fear]=item;
        return true;
    }

    public int get(){//获取头部并出队

        if(isEmpty())
            throw new RuntimeException("队列为空");

        front++;
        return queue[front];

    }
    public int peek(){//查看头部元素

        if(isEmpty())
            throw new RuntimeException("队列为空");

        return queue[front+1];

    }

    public String toString(){
        String content="";
        if (isEmpty())
            content+="empty";
        for(int i=front+1;i<=fear;i++){
            content+=queue[i];
        }
        return content;
    }

}